home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Essential Structures / HelloCenteredMeasured / HelloCenteredMeasured.cs next >
Encoding:
Text File  |  2001-01-15  |  1.0 KB  |  31 lines

  1. //----------------------------------------------------
  2. // HelloCenteredMeasured.cs ⌐ 2001 by Charles Petzold
  3. //----------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class HelloCenteredMeasured: Form
  9. {
  10.      public static void Main() 
  11.      {
  12.           Application.Run(new HelloCenteredMeasured()); 
  13.      }
  14.      public HelloCenteredMeasured()
  15.      {
  16.           Text = "Hello Centered Using MeasureString";
  17.           BackColor = SystemColors.Window;
  18.           ForeColor = SystemColors.WindowText;
  19.           ResizeRedraw = true;
  20.      }
  21.      protected override void OnPaint(PaintEventArgs pea)
  22.      {
  23.           Graphics grfx      = pea.Graphics;
  24.           string   str       = "Hello, world!";
  25.           SizeF    sizefText = grfx.MeasureString(str, Font);
  26.  
  27.           grfx.DrawString(str, Font, new SolidBrush(ForeColor), 
  28.                           (ClientSize.Width  - sizefText.Width)  / 2, 
  29.                           (ClientSize.Height - sizefText.Height) / 2);
  30.      }
  31. }